package com.amado.webservice;
 
import java.io.IOException;
import java.rmi.RemoteException;

import javax.xml.bind.JAXBException;

import com.amado.webservice.create.XxfbptserviceStub;
import com.amado.webservice.entity.Response;
import com.amado.webservice.entity.response.Body;
import com.amado.webservice.entity.response.Head;
import com.amado.webservice.entity.response.Return;
import com.amado.webservice.util.DESCorder;
import com.amado.webservice.util.XmlUtil;
 
public class TestReturnHeadBody {
	public static void main(String[] args) {
		testXmlToBean();
		testBeanToXml();
	}

	public static void testXmlToBean() {
		String xml = "<return>\r\n" + 
				"<head>\r\n" + 
				"<!-- 和请求相同 -->\r\n" + 
				"<yhdh>用户代号</yhdh>\r\n" + 
				"<!-- 和请求相同 -->\r\n" + 
				"<ip>IP</ip>\r\n" + 
				"<!-- 和请求相同 -->\r\n" + 
				"<lsh>流水号</lsh>\r\n" + 
				"<!-- 0000-成功,0010-未授权,0011-时间间隔设置错误或超出时间间隔,0012-请求数据已过期,其它-接口异常  -->\r\n" + 
				"<fhz>返回值</fhz>\r\n" + 
				"<!-- 成功为提示信息,失败为具体原因 -->\r\n" + 
				"<fhz-msg>返回描述</fhz-msg>\r\n" + 
				"<!-- 其他需提示的信息 -->\r\n" + 
				"<bz>备注</bz>\r\n" + 
				"</head>\r\n" + 
				"<body>\r\n" + 
				"<!--  取批次时间间隔.单位:小时.如6表示请求批次号最多在连续的6个小时内. -->\r\n" + 
				" <sjjg>时间间隔</sjjg>\r\n" + 
				"<!--  取批次最早时间.单位:天.如30表示请求批次号最早>=trunc(sysdate)-30. -->\r\n" + 
				"<sjc>最早时间</sjc>\r\n" + 
				"<!-- 16位唯一存在的序列号 -->\r\n" + 
				"<pch>批次号</pch>\r\n" + 
				"<!-- < pch >更多批次号</ pch > -->\r\n" + 
				"</body>\r\n" + 
				"</return>";
		try {
			Return return_ = XmlUtil.xmlToBean(xml, Return.class);
			System.out.println(return_);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public static void testBeanToXml() {
		Body body = new Body();
		body.setPch("pch");
		Head head = new Head();
		head.setBz("bz00123");
		Return return_ = new Return();
		return_.setBody(body);
		return_.setHead(head);
		String xmlString = null;
		try {
			//java bean对象转换成xml结构
			xmlString = XmlUtil.beanToXml(return_, Return.class);
		} catch (JAXBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(xmlString);

	}
		
}
